package jsyf.oa.web.system;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.TargetFacade;
import jsyf.oa.facade.system.TargetRoleFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by WHH-PC on 2018/1/26.
 */
@Api(value = "目标接口", description = "目标接口")
@Controller
@RequestMapping("/target")
public class TargetController {
    @Resource
    private TargetRoleFacade targetRoleFacade;
    @Resource
    private TargetFacade targetFacade;

    @RequestMapping(value = "/saveTargetRole.json", method = RequestMethod.POST)
    public void saveTargetRole(HttpServletResponse response, @RequestBody String jsonData) {
        String id = targetRoleFacade.save(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @ApiOperation(
            value = "大客户配置目标",
            notes = "大客户配置目标",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{salerRoleId: \"2017121618124450A5DA77A2B50B9D35\",salerRoleName: \"区域经理\",salerFaceTarget:3,companyId:\"20171216174747FEAED47B7D5A930A0E\",createUserId:\"2017121913324829A05E5B9CA7E3F908\",salerTelTarget:0}", dataType = "String", paramType = "body")
    @RequestMapping(value = "/saveBigCustomer.json", method = RequestMethod.POST)
    public void saveBigCustomer(HttpServletResponse response, @RequestBody String jsonData) {
        String id = targetRoleFacade.saveBigCustomer(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @RequestMapping(value = "/saveTarget.json", method = RequestMethod.POST)
    public void saveTarget(HttpServletResponse response, @RequestBody String jsonData) {
        String id = targetFacade.save(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @RequestMapping(value = "/getTargetList.json", method = RequestMethod.POST)
    public void getTargetList(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject json = JSON.parseObject(jsonData);
        List<JSONObject> jsonObject = targetFacade.getTargetList(json);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(jsonObject));
    }

    @RequestMapping(value = "/getTargetById.json", method = RequestMethod.POST)
    public void getTargetById(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject json = JSON.parseObject(jsonData);
        JSONObject jsonObject = targetFacade.getById(json.get("id").toString());
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
    }

    @RequestMapping(value = "/getTargetRole.json", method = RequestMethod.POST)
    public void getTargetRole(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject json = JSON.parseObject(jsonData);
        List<JSONObject> list = targetRoleFacade.getTargetRole(json.get("companyId").toString());
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getCompanyTarget.json", method = RequestMethod.POST)
    public void getCompanyTarget(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject json = JSON.parseObject(jsonData);
        List<JSONObject> jsonObject = targetFacade.getCompanyTarget();
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(jsonObject));
    }
}
